//  This file was generated with SpriteHelper
//  http://www.spritehelper.org
//
//  SpriteHelperLoader.h 
//  Created by Bogdan Vladu
//  Copyright 2011 Bogdan Vladu. All rights reserved.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  This software is provided 'as-is', without any express or implied
//  warranty.  In no event will the authors be held liable for any damages
//  arising from the use of this software.
//  Permission is granted to anyone to use this software for any purpose,
//  including commercial applications, and to alter it and redistribute it
//  freely, subject to the following restrictions:
//  The origin of this software must not be misrepresented; you must not
//  claim that you wrote the original software. If you use this software
//  in a product, an acknowledgment in the product documentation would be
//  appreciated but is not required.
//  Altered source versions must be plainly marked as such, and must not be
//  misrepresented as being the original software.
//  This notice may not be removed or altered from any source distribution.
//  By "software" the author refers to this code file and not the application 
//  that was used to generate this file.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Version history
//  v1.0 First draft
//  v1.1 Added more animation methods
////////////////////////////////////////////////////////////////////////////////////////////////////////



#ifndef __SPRITE_HELPER_LOADER__
#define __SPRITE_HELPER_LOADER__

#include "cocos2d.h"
#include "Box2D/Box2D.h"
#include "map"

using namespace cocos2d;

//Pixel to metres ratio. Box2D uses metres as the unit for measurement.
//This ratio defines how many pixels correspond to 1 Box2D "metre"
//Box2D is optimized for objects of 1x1 metre therefore it makes sense
//to define the ratio so that your most common object type is 1x1 metre.
#define PTM_RATIO 32 //you should only keep this here so you don't change it everywhere - so you should delete it from everywhere else

typedef std::map<std::string, std::string> LHDictionary;
class SpriteInfo;

class SpriteHelperLoader
{
	
public:
	
	/**
	 Constructor - create a new SpriteHelperLoader object\n
	 
	 @param[in] sceneFile - a string representing the SpriteHelper scene file name 
	 
	 @code 
	 SpriteHelperLoader* loader = new SpriteHelperLoader("Scene1.pshs");
	 @endcode
	 */
	SpriteHelperLoader(const std::string& levelFile);
	
	////////////////////////////////////////////////////////////////////////////
	
	virtual ~SpriteHelperLoader();
	
	////////////////////////////////////////////////////////////////////////////

    
    CCSprite* spriteWithUniqueName(const std::string &name, 
                                   const CCPoint& position, 
                                   CCLayer* layer);
    
    CCSprite* spriteWithUniqueName(const std::string& name, 
                                   const CCPoint& position);
    
    CCSprite* spriteWithUniqueName(const std::string& name);
    
////////////////////////////////////////////////////////////////////////////////
    
    CCSprite* animSpriteWithUniqueName(const std::vector<std::string>& frames,
                                       const CCPoint& position,
                                       CCLayer* layer,
                                       const float& delay,
                                       const int& noOfRepeats,
                                       CCAction** animAction);
    
    CCSprite* animSpriteWithUniqueName(const std::string& name,
                                       const CCPoint& position,
                                       CCLayer* layer,
                                       const int& frameNo,
                                       const float& delay,
                                       const int& noOfRepeats,
                                       CCAction** animAction);

    CCSprite* animSpriteWithUniqueName(const std::string& name,
                                       const int& startFrameNo,
                                       const int& endFrameNo,
                                       const CCPoint& position,
                                       CCLayer* layer,
                                       const float& delay,
                                       const int& noOfRepeats,
                                       CCAction** animAction);

	std::vector<std::string> frameListWithAnimName( const std::string& name );

////////////////////////////////////////////////////////////////////////////////
    
	CCAction* actionForAnimName(const std::string& name, 
                              const float& delay);

    CCAction* actionForFrames(const std::vector<std::string>& frameNames, 
                              const float& delay);

    CCAction* actionForFrames(const std::string& name, 
                              const int& frameNo, 
                              const float& delay);
    
    CCAction* actionForFrames(const std::string& name, 
                              const int& startFrameNo,
                              const int& endFrameNo,
                              const float& delay);

////////////////////////////////////////////////////////////////////////////////
    
    b2Body* bodyWithUniqueName(const std::string& uniqueName, 
                               const CCPoint& position,
                               CCLayer* layer,
                               b2World* world);
    
    b2Body* animBodyWithUniqueName(const std::string& name,
                                   CCSprite* animSprite,
                                   b2World* world);

	
////////////////////////////////////////////////////////////////////////////////
private:
	
	SpriteHelperLoader(){}
	
	std::vector<SpriteInfo*> lhSprites;
		
	void setSpritePropertiesFromMap(CCSprite* ccsprite, LHDictionary &spriteMap);
	
	void setFixtureDefPropertiesFromMap(LHDictionary& physic,
										b2FixtureDef *shapeDef);

	b2Body* b2BodyFromMap(LHDictionary& properties,
						  std::vector<std::vector<std::string> >&fixtures,
						  CCSprite* ccsprite,
						  b2World* world);
	
    CCSprite* spriteFromMap(LHDictionary &spriteMap);
    
    LHDictionary* propertyForName(const std::string& name);
    SpriteInfo* spriteInfoForName(const std::string& name);
    
	void key(const std::string& arg);
	void pushValue(const std::string& arg);
	void arrayBegin();
	void noArray();
	void arrayEnd();
	void dictBegin();
	void dictEnd();
	std::string valueForField(const std::string& field);
	
	void loadSpriteHelperSceneFile(const std::string& levelFile);
	
	void assertMessage(bool value, const std::string message);
};

#endif
